package com.itheima.zuoye.zuoye1;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import org.apache.commons.io.FileUtils;

import java.io.*;
import java.nio.file.Files;
import java.util.ArrayList;

public class Test {
    public static void main(String[] args) throws FileNotFoundException {

        String path = "day14_IO\\src\\com\\itheima\\zuoye\\zuoye1\\p01";
        String path1 = "day14_IO\\src\\com\\itheima\\zuoye\\zuoye1\\p02";

        File paths = new File(path);
        File path2 = new File(path1);

        if (paths.isDirectory()) {
            File[] files = paths.listFiles();
            if (files != null) {
                for (File file : files) {
                    if (file.isFile()) {
                        File file1 = new File(path1, file.getName());
                        FileUtil.copy(file, file1, true);
                    }
                }
            }
        }
        File[] files1 = path2.listFiles();
        if (files1 != null) {
            for (File file : files1) {
                if (file.isFile()) {
                    if (file.getName().endsWith(".java")){
                        String name = StrUtil.replaceLast(file.getName(), ".java", ".txt");
                        File newFile = new File(file.getParent(), name);
                        file.renameTo(newFile);

                    }
                }
            }
        }

        System.out.println("复制过程已完成");
    }
}





